package com.sky.controller.admin;

import com.sky.result.Result;
import com.sky.service.DataStatisticsService;
import com.sky.vo.OrderReportVO;
import com.sky.vo.SalesTop10ReportVO;
import com.sky.vo.TurnoverReportVO;
import com.sky.vo.UserReportVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.time.LocalDate;

@Api(tags = "数据统计接口")
@Slf4j
@RequestMapping("/admin/report")
@RestController
public class DataStatisticsController {

    @Autowired
    private DataStatisticsService dataStatisticsService;

    /**
     * 导出报表接口
     * @return
     */
    @ApiOperation("导出报表接口")
    @GetMapping("/export")
    public Result exportExcel(){

        return Result.success("OK");
    }

    /**
     * 查询销量排名top10
     * @return
     */
    @ApiOperation("查询销量排名top10")
    @GetMapping("/top10")

    public Result getTop10(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
                           @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate end){
        log.info("查询日期开始时间{}",begin);
        log.info("查询日期结束时间{}",end);

        SalesTop10ReportVO result = dataStatisticsService.getTop10(begin,end);
        return Result.success(result);
    }
    /**
     * 用户统计
     * @return
     */
    @ApiOperation("用户统计")
    @GetMapping("/userStatistics")
    public Result uerStatistics(@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate begin,
                                @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate end){
        log.info("开始时间：{}",begin);
        log.info("结束时间：{}",end);
        UserReportVO result = dataStatisticsService.userStatistics(begin,end);
        log.info("输出的结果为：{}",result);

        return Result.success(result);
    }

    /**
     * 营业额统计
     * @return
     */
    @ApiOperation("营业额统计")
    @GetMapping("/turnoverStatistics")
    public Result turnoverStatistics(@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate begin,
                                     @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate end){
        TurnoverReportVO result = dataStatisticsService.turnoverStatistics(begin,end);
        return Result.success(result);
    }

    /**
     * 订单统计
     * @return
     */
    @ApiOperation("订单统计")
    @GetMapping("/ordersStatistics")
    public Result ordersStatistics(@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate begin,
                                   @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate end){

        OrderReportVO result = dataStatisticsService.ordersStatistics(begin,end);

        return Result.success(result);
    }

}
